<?php
/**
 *   Creates a pager for the Project Details Page
 *   This will create the Previous and Next buttons only, the name of the tag is created in another template.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $options['type'] will either be ul or ol.
 * @ingroup views_templates
 */
	global $base_url;

	//Get Array of results from view object
  //This returns all the projects within the term
	$results = $view->result;

	//Find the index where the current node lives
	$i=0;
	foreach ($results as $id => $row){
    	if ($row->nid == arg(1)){
    		$myindex=$i;
    	}
    	$i++;
    }
?>
<?php 
  //If the project isn't published Drupal will spit out an error because the project doesn't exist in the pager just yet
  //$myindex doesn't exist and cause an error
  //Therefore, the pager will be disabled when the project isn't published
  if(isset($myindex)): ?> 
    <?php print $wrapper_prefix; ?>
      <?php print $list_type_prefix; ?>
       	 <li class="previous">
     	 	<?php if(isset($rows[$myindex-1])):?>
     	 		<?php //Create URL for Previous Link 
     	 			$prevURL=$base_url.'/'.drupal_get_path_alias('node/'.$results[$myindex-1]->nid).'?term='.$view->args[0];
     	 		?>
     	 		<a href="<?php print $prevURL;?>">previous</a>
     	 	<?php endif;?>
     	 </li>
      
     	 <li class="next">
     	 	 <?php if(isset($rows[$myindex+1])):?>
     	 	 	<?php //Create URL for Next Link 
     	 	 		$nextURL=$base_url.'/'.drupal_get_path_alias('node/'.$results[$myindex+1]->nid).'?term='.$view->args[0];
     	 	 	?>
     	 		<a href="<?php print $nextURL;?>">next</a>
     	 	<?php endif;?>
     	 </li>

      <?php print $list_type_suffix; ?>
    <?php print $wrapper_suffix; ?>
<?php endif;?>

